package com.igoal.entity;

import java.util.Date;

import javax.persistence.AssociationOverride;
import javax.persistence.AssociationOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.JoinColumn;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.compass.annotations.SearchableProperty;

@Entity
@Table(name="goal_category")
@AssociationOverrides({
	@AssociationOverride(name="pk.category", joinColumns=@JoinColumn(name="category_id")),
	@AssociationOverride(name="pk.goal", joinColumns=@JoinColumn(name="goal_id"))
})
public class GoalCategory extends BaseObject implements Audit {
	private static final long serialVersionUID = -1684055381322754176L;
	private GoalCategoryPk pk = new GoalCategoryPk();
	private Date createDate;
	private Date updateDate;
	private DataStatus status;
	
	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
 
        UserGoal that = (UserGoal) o;
 
        if (getPk() != null ? !getPk().equals(that.getPk()) : that.getPk() != null) return false;
 
        return true;
	}

	@Override
	public int hashCode() {
		return (getPk() != null ? getPk().hashCode() : 0);
	}

	@Override
	public String toString() {
		if(this.pk != null){
			return pk.getGoal().toString() + " of " + pk.getCategory().toString();
		}
		return null;
	}
	
	@EmbeddedId
	public GoalCategoryPk getPk() {
		return pk;
	}

	public void setPk(GoalCategoryPk pk) {
		this.pk = pk;
	}

	@Transient
	public Goal getGoal(){
		return pk.getGoal();
	}
	
	public void setGoal(Goal goal){
		pk.setGoal(goal);
	}
	
	@Transient
	public Category getCategory(){
		return pk.getCategory();
	}
	
	public void setCategory(Category category){
		pk.setCategory(category);
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(nullable=false, name="cdate")
	public Date getCreateDate() {
		return createDate;
	}

	@Enumerated(EnumType.STRING)
	@Column(nullable=false, name="status")
	@SearchableProperty
	public DataStatus getStatus() {
		return status;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(nullable=false, name="mdate")
	public Date getUpdateDate() {
		return updateDate;
	}

	public void setCreateDate(Date date) {
		this.createDate = date;
	}

	public void setStatus(DataStatus dataStatus) {
		this.status = dataStatus;
	}

	public void setUpdateDate(Date date) {
		this.updateDate = date;
	}
}
